/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sddengine;

import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
/**
 *
 * @author jbm
 */
public class PlayerSprite extends AnimatedSprite
{
    int right = 1;
    int left = 2;
    int standing = 3;
    int walking = 4;
    
    TestGame gameInput;
    
    public PlayerSprite(BufferedImage[] images, int time, int x, int y, TestGame game)
    {
        super(images, time, x, y);
        
        this.gameInput = game;
       
        
        
    }
    
    @Override
    public void update()
    {
        super.update();
        
        if(gameInput.keyDown(KeyEvent.VK_W))
        {
            this.setVerticalSpeed(-2);
        }
        
        
        if(gameInput.keyDown(KeyEvent.VK_A))
        {
            this.setAnimation(walking, left);
            this.setHorizontalSpeed(-2);
        }
        
        
        if(gameInput.keyDown(KeyEvent.VK_D))
        {
            this.setAnimation(walking, right);
            this.setHorizontalSpeed(2);
        }
        
        
        if(gameInput.keyDown(KeyEvent.VK_S))
        {
            this.setVerticalSpeed(2);
        }
        
    
    }
    
    @Override
    protected void animationChanged(int oldStat, int oldDir, int status, int direction) 
    {
        if(direction == right)
        {
            if(status == walking)
            {
                this.setAnimationFrames(0, 15);
                
            }
            if(status == standing)
            {
                this.setAnimationFrames(16, 31);
            }
        }
        else if(direction == left)
        {
            if(status == walking)
            {
                this.setAnimationFrames(16, 31);

            }
            if(status == standing)
            {
                this.setAnimationFrames(13, 13);
            }
        }
    }
}
